package com.shigen.demo.atguigu;

import java.util.concurrent.atomic.AtomicReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * 原子引用
 *
 * @author shigenfu
 * @date 2022/5/21 10:01 下午
 */

@Data
@ToString
@AllArgsConstructor
class User {

  String username;
  int age;
}

public class AtomicReferenceDemo {

  public static void main(String[] args) {
    AtomicReference<User> atomicReference = new AtomicReference<>();

    User shigen = new User("shigen", 12);
    User agen = new User("agen", 34);
    atomicReference.set(shigen);
    System.out.println(atomicReference.compareAndSet(shigen, agen) + "  " + atomicReference.get().toString());
    System.out.println(atomicReference.compareAndSet(shigen, agen) + "  " + atomicReference.get().toString());


  }
}
